fix(responses): repair blank/orphan tool_call_id before provider dispatch#74
Merged
Merged
Conversation
…atch
Codex Desktop's bundled-plugin (Browser/Computer-use) function_call_output
items arrive without a usable call_id, which flattened to an empty
tool_call_id and 400'd at Moonshot ("Invalid request: tool_call_id is not
found"). The old repair loop in openrouter-utils couldn't catch it because
"" === "" read as a match.
Add a shared repairToolCallIds() helper that backfills synthetic ids on
assistant tool_calls, re-links blank/drifted tool_call_ids to the nearest
preceding assistant tool_call, and drops true orphans. Wire it into both
convertResponsesToChat() and convertAnthropicMessagesToOpenRouter().
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… tap) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Match the README: verify step + auto-tracked tap upgrade note. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Codex Desktop (via
/v1/responses) was failing with:Note the double space — the
tool_call_idwas an empty string. Codex's bundled-plugin (@Browser/@Computer-use)function_call_outputitems and synthetic"unsupported call: shell"outputs arrive without a usablecall_id. InconvertResponsesToChat()both the assistanttool_calls[].id(call_id || id) and thetoolmessage'stool_call_id(call_id) flattened to"", and the orchestrator forwarded the empty id to Moonshot.The existing repair loop in
openrouter-utils.jscouldn't catch it because"" === ""counted as a match, andresponses-format.jshad no repair pass at all.Fix
New shared helper
src/clients/tool-call-repair.js→repairToolCallIds(messages)(operates on OpenAI-format message arrays):call_auto_N) onto any assistanttool_callsentry missing one.toolmessage to an unused tool_call id on the nearest preceding assistant — treating a blanktool_call_idas a mismatch (the case the old loop missed).toolmessage with no assistant tool_call to attach to (a dangling id is a hard 400 — dropping is strictly safer than forwarding).Wired into both conversion boundaries:
responses-format.jsconvertResponsesToChat()— fixes the ids at the source.openrouter-utils.jsconvertAnthropicMessagesToOpenRouter()— last stop before Moonshot/OpenRouter (replaces the old broken repair loop).Also updates the README Homebrew section (verify + upgrade steps).
Verification
function_call/function_call_outputpairs): everytool_call_idnow comes out non-blank and matched; drifted ids re-link; true orphans drop.node --test test/format-conversion.test.js test/passthrough-mode.test.js test/openrouter-error-resilience.test.js→ 48 passing.responses-format.jsare unrelated).🤖 Generated with Claude Code